<template>
    <div  
    class="avatar"
    :style="{
      width: width + 'px',
      height: width + 'px',
      'border-radius': width / 2 + 'px',
    }"
    >
    <!--头像接口-->
    <el-image
      v-if="userId"
      :style="{
        width: width + 'px',
        height: width + 'px',
        'border-radius': width / 2 + 'px',
      }"
      :src="url"
      fit="scale-down"
      loading="lazy"
      @click="goToUcenter"
    >
    </el-image>
    <div v-else class="no-login">未登录</div>

</div>

</template>

<script setup>
import { getCurrentInstance } from "vue";
import { useRouter } from "vue-router";
const { proxy } = getCurrentInstance();
const router = useRouter();

const props = defineProps({
  userId: {
    type: String,
  },
  width: {
    type: Number,
    default: 60,
  },
  addLink: {
    type: Boolean,
    default: true,
  },
  url: {
    type: String,
  },
});
//点击头像去用户中心，改名字
const goToUcenter = () => {
  if (props.addLink) {
    router.push("/user/" + proxy.userId);
  }
};

</script>

<style lang="scss">

</style>